'use strict';
const dayjs = require("dayjs");
module.exports = app => {
    const { STRING, INTEGER, DATE } = app.Sequelize;
    const User = app.model.define(
        'User',
        {
            id: { type: INTEGER, primaryKey: true, autoIncrement: true },
            nickname: STRING(255),
            email: STRING(255),
            phone: STRING(255),
            avatar_url: STRING(255),
            status: INTEGER,
            wx_openid: STRING(255),
            role: { type: INTEGER, defaultValue: 0 },
            audit: { type: INTEGER, defaultValue: -1 },
            audit_desc: STRING(255),
            company_name: STRING(255),
            address: STRING(255),
            balance: { type: 'DECIMAL(10,2)', defaultValue: 0.00 },
            parent_user_id: INTEGER,
            del_flag: { type: INTEGER, defaultValue: 0 },
            create_time: {
                type: DATE,
                get() {
                    return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            updated_time: {
                type: DATE,
                get() {
                    return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            }
        },
        {
            tableName: 'user',
            timestamps: true, // 启用时间戳(createdAt, updatedAt)
            createdAt: 'create_time',
            updatedAt: 'updated_time'
        }
    );
    return User;
};
